package com.jyc.service;

import com.jyc.entity.shop.Item;
import com.jyc.entity.web.Goupiaoxinxi;
import com.jyc.mapper.web.GoupiaoxinxiMapper;
import com.jyc.util.HttpResult;
import com.jyc.vo.shop.ItemChartVO;
import com.jyc.vo.web.GoupiaoxinxiVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Service
@Transactional
public class WebService {
    @Autowired(required = false)
    private GoupiaoxinxiMapper goupiaoxinxiMapper;

    public List<Goupiaoxinxi> getItemList() {
        return goupiaoxinxiMapper.selectByExample(null);
    }


    public List<GoupiaoxinxiVO> showLine() {
        return goupiaoxinxiMapper.shouLine();
    }

    public List<GoupiaoxinxiVO> showPillar() {
        return goupiaoxinxiMapper.showPillar();
    }

    public List<GoupiaoxinxiVO> showPie() {
        return goupiaoxinxiMapper.showPie();
    }


    public Set<List> show3DByNum() {
        Set<List> dataSet = new LinkedHashSet<>();
        List<String> times = goupiaoxinxiMapper.selectTime();
        for (String time : times) {
            if (dataSet.size() == 0) {
                List first = new ArrayList();
                first.add("售出日期");
                first.add("景点");
                first.add("购票数");
                dataSet.add(first);
            }
            List<GoupiaoxinxiVO> itemChartVOS = goupiaoxinxiMapper.showOneInfoByTime(time);
            for (GoupiaoxinxiVO goupiaoxinxiVO : itemChartVOS) {
                List tempList= new ArrayList();
                tempList.add(time);
                tempList.add(goupiaoxinxiVO.getJingdianmingcheng());
                tempList.add(goupiaoxinxiVO.getTotalticket());
                dataSet.add(tempList);
            }
        }
        return dataSet;
    }

    public Set<List> show3DByPrice() {
        Set<List> dataSet = new LinkedHashSet<>();
        List<String> times = goupiaoxinxiMapper.selectTime();
        for (String time : times) {
            if (dataSet.size() == 0) {
                List first = new ArrayList();
                first.add("售出日期");
                first.add("景点");
                first.add("盈利");
                dataSet.add(first);
            }
            List<GoupiaoxinxiVO> itemChartVOS = goupiaoxinxiMapper.showTotalPriceByTime(time);
            for (GoupiaoxinxiVO goupiaoxinxiVO : itemChartVOS) {
                List tempList= new ArrayList();
                tempList.add(time);
                tempList.add(goupiaoxinxiVO.getJingdianmingcheng());
                tempList.add(goupiaoxinxiVO.getTotalmoney());
                dataSet.add(tempList);
            }
        }
        return dataSet;
    }
}
